function [ u ] = controle_regiao(z, zp, ref, index_old)
%UNTITLED Summary of this function goes here
%   Detailed explanation goes here
%     Regions{1,1} = [4.78704654710077e-07 4.32038267451417e-05 -4.32038267451417e-05;3.56427518063283e-07 3.20960403240000e-05 -3.20960403240000e-05;2.33254440054926e-07 2.09982000000000e-05 -2.09982000000000e-05;1.11087792405584e-07 1.00000000000000e-05 -1.00000000000000e-05];
%     Regions{1,2} = [-0.00200023340760277;-0.00200020848996826;-0.00200015922494611;-0.00200008640765349];
%     Regions{1,3} = [8.67361737988404e-19 1.11022302462516e-16 -1.11022302462516e-16];
%     Regions{1,4} = 20;
% 
%     Regions{2,1} = [4.78704654710077e-07 4.32038267451417e-05 -4.32038267451417e-05;3.56427518063283e-07 3.20960403240000e-05 -3.20960403240000e-05;2.33254440054926e-07 2.09982000000000e-05 -2.09982000000000e-05;1.11087792405584e-07 1.00000000000000e-05 -1.00000000000000e-05];
%     Regions{2,2} = [-0.00200023340760277;-0.00200020848996826;-0.00200015922494611;-0.00200008640765349];
%     Regions{2,3} = [8.67361737988404e-19 1.11022302462516e-16 -1.11022302462516e-16];
%     Regions{2,4} = 20;
%     
%     Regions{3,1} = [4.78703420782945e-07 4.32037156683882e-05 -4.32037156683882e-05;3.56426285241029e-07 3.20959293467065e-05 -3.20959293467065e-05;2.33253218301385e-07 2.09980900190998e-05 -2.09980900190998e-05];
%     Regions{3,2} = [-0.00200021119129229;-0.00200018629355064;-0.00200013722781575];
%     Regions{3,3} = [0 0 0];
%     Regions{3,4} = 20;
%     
%     Regions{4,1} = [4.78697982771369e-07 4.32032261237748e-05 -4.32032261237748e-05;3.56420873021822e-07 3.20954421239923e-05 -3.20954421239923e-05];
%     Regions{4,2} = [-0.00200016456055563;-0.00200013988398253];
%     Regions{4,3} = [0 0 0];
%     Regions{4,4} = 20;
%     
%     Regions{5,1} = [4.78685319428626e-07 4.32020857989093e-05 -4.32020857989093e-05];
%     Regions{5,2} = -0.00200009349721787;
%     Regions{5,3} = [0 0 0];
%     Regions{5,4} = 20;
%     
%     Regions{6,1} = [0.00478662942601910 0.432000662559059 -0.432000662559059;1 0 0;-1 0 0;0 -1 0;-0.0100000000000000 -1 0;-0.0109977213370574 -0.999956799933744 -4.32000662559059e-05;-0.0110969574893205 -0.999920394900287 -7.96050997134423e-05;-0.0111066300134038 -0.999895765075601 -0.000104234924398603;-0.0111074844499133 -0.999883307693424 -0.000116692306575610;0 0 1;0 0 -1];
%     Regions{6,2} = [10;1000;1000;1;1;1;1;1;1;11;1];
    hue = load('regions_test.mat');
    Regions = hue.Regions;
    index = index_old;
    for j = 1:size(Regions,1)
            A_CRi = Regions{j,1};
            b_CRi = Regions{j,2};
            flag = 0;
            for k = 1:size(A_CRi,1)
                if(A_CRi(k,:)*[z; zp ; ref] > b_CRi(k))
                    flag = 1;
                end
            end
            if flag == 0
                index = j;
            end
    end
    u = Regions{index,3}*[z; zp ; ref] + Regions{index,4};
end

